package com.twu.biblioteca.view.command;

import com.google.inject.Inject;

import com.twu.biblioteca.controller.MovieController;
import com.twu.biblioteca.entity.Movie;
import com.twu.biblioteca.view.console.ConsoleViewController;

public class MovieCheckoutCommand extends Command {
  private final MovieController controller;

  @Inject
  public MovieCheckoutCommand(MovieController controller) {
    this.controller = controller;
  }

  @Override
  public void execute(ConsoleViewController viewController) {
    int availableBookSize = viewController.getAvailableMovieSize();
    this.consoleWriter.display(String.format("Enter a number to checkout a Movie [1 to %d]: ",
        availableBookSize));
    int itemToCheckout = this.consoleReader
        .readLineAndConvertInt(availableBookSize, "Enter a number to checkout a Movie [1 to %d]: ");
    Movie movieToCheckout = viewController.getMovieToCheckout(itemToCheckout);
    controller.checkout(movieToCheckout);
  }
}
